
package com.bash.carrep.ui.util;

import com.vaadin.data.Item;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;

/**
 *
 * @author bash
 */
public class LoginFieldFactory extends com.bash.carrep.ui.util.PojoFieldFactory {

    @Override
    public Field createField(Item item, Object propertyId, Component uiContext) {

        PasswordField pf = new PasswordField("Mot de passe");

        Field f = super.createField(item, propertyId, uiContext);

        if ("username".equals(propertyId)) {
            TextField tf = (TextField) f;
            tf.setRequired(true);
            tf.setCaption("Login");
            tf.setNullRepresentation("");
            tf.setRequiredError("Veuillez donner le login");
            tf.setWidth("15em");
            
            tf.addValidator(new StringLengthValidator("Le login doit avoir entre 1 et 10 caractères", 1, 10, false));
        }

        if ("password".equals(propertyId)) {
            pf.setRequired(true);
            pf.setWidth("15em");
              pf.setNullRepresentation("");
            pf.setRequiredError("Veuillez donner le mot de passe");
            return pf;
        }



        return f;
    }
}
